package com.nl.controller.web.controller;

import java.io.IOException;
import java.io.InputStream;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.nl.controller.web.service.CRMInterfaceService;

import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
@RequestMapping("crmInterface")
public class CRMInterfaceController {

	@Autowired
	private CRMInterfaceService cRMFindMgrService;

	@ApiOperation(value = "项目信息查询", notes = "项目信息查询")
	@RequestMapping("queryMgrName")
	private JSONObject findMgrName(
			//@RequestParam(value = "cRMReqMgrList", required = true) String cRMReqMgrList
			HttpServletRequest request
			) {
		InputStream in;
		 String reqJson="";
		 JSONObject map = new JSONObject();
		try {
			in = request.getInputStream();
			reqJson = IOUtils.toString(in, "utf-8");
			log.info("cRMReqMgrList:"+reqJson);
		} catch (IOException e) {
			e.printStackTrace();
			log.error(e.toString());
		}
		
		if (null== reqJson) {
			map.put("resp", "请输入请求参数");
			return map;
		}
		
		map = cRMFindMgrService.selectMgrNameLike(/*cRMReqMgrList*/reqJson);
		log.info("【CRM项目信息查询接口】返回数据：{}", map);
		return map;
	}
	
/*    @ApiOperation(value = "开户信息同步", notes = "开户信息同步")
    @PostMapping("synInfo")
    public JSONObject addUser(
//          @RequestParam(value = "cRMOpenInfo") String cRMOpenInfo,
            HttpServletRequest request        
    ) {
    	InputStream in;
		 String reqJson="";
		try {
			in = request.getInputStream();
			reqJson = IOUtils.toString(in, "utf-8");
			log.info("cRMOpenInfo:"+reqJson);
		} catch (IOException e) {
			e.printStackTrace();
			log.error(e.toString());
		}
		JSONObject map=new JSONObject();
		if (null== reqJson) {
			map.put("resp", "请输入请求参数");
			return map;
		}
    	 map= cRMFindMgrService.addOpenInfo(cRMOpenInforeqJson);
    	 log.info("【CRM开户信息同步】返回数据：{}", map);
    	 return map;
    }*/
	
	
	
    @ApiOperation(value = "开户信息同步", notes = "开户信息同步")
    @PostMapping("synInfo")
    public JSONObject addUser(
          //@RequestParam(value = "cRMOpenInfo") String cRMOpenInfo
          HttpServletRequest request        
    ) {
    	InputStream in;
		 String reqJson="";
		 JSONObject map=new JSONObject();
		try {
			in = request.getInputStream();
			reqJson = IOUtils.toString(in, "utf-8");
			log.info("cRMOpenInfo:"+reqJson);
		} catch (IOException e) {
			e.printStackTrace();
			log.error(e.toString());
		}
		
		if (null== reqJson) {
			map.put("resp", "请输入请求参数");
			return map;
		}
    	 map= cRMFindMgrService.addOpenInfo(/*cRMOpenInfo*/ reqJson);
    	 log.info("【CRM开户信息同步】返回数据：{}", map);
    	 return map;
    }
    
    @ApiOperation(value = "精准政务开户信息同步测试", notes = "开户信息同步")
    @RequestMapping("JZZWOpenTest")
    public Map<String, Object> JZZW(
            @RequestParam(value = "cRMOpenInfo") String cRMOpenInfo  /*,HttpServletRequest request*/        
    ) {
    	 //cRMOpenInfo  = "{\"ecId\":\"1100099090909\",\"ecName\":\"xx街道办\",\"sendNumber\":\"10657016110001\",\"userId\":\"1101\",\"feeId\":\"2000015531\",\"feeDetail\":\"1000\",\"ops\":\"1\",\"streamSeq\":\"20190809110306100001\"}";
    	 Map<String, Object> map= cRMFindMgrService.JZZW(cRMOpenInfo);
    	 log.info("【准政务开户信息同步测试】返回数据：{}", map);
    	 return map;
    }
    


}
